
function transform(el,attr,val){
  if(typeof el != 'undefined' && typeof attr != 'undefined'){

     if(!el.transform){
      el.transform = {};
     }

     if(typeof val == 'undefined'){
      //获取值
      return el.transform[attr] || null;
     }else{
      //设置值
      el.transform[attr] = val;

      var _setStr = '';

      for(var per in el.transform){

        if(per.indexOf('rotate')!=-1 || per.indexOf('skew')!=-1){
          _setStr+=per+'('+ el.transform[per] +'deg) ';
        }else if(per.indexOf('scale')!=-1){
          _setStr+=per+'('+ el.transform[per] +') ';
        }else if(per.indexOf('translate')!=-1){
          _setStr+=per+'('+ el.transform[per] +'px) ';
        }else{
          _setStr+=per+'('+ el.transform[per] +'px) ';
        }

      }

      el.style.WebkitTransform = el.style.transform = _setStr;

      return _setStr;

     }

  }else{
    return null;
  }
}

function css(el,attr,val){

  if(typeof el != 'undefined' && typeof attr != 'undefined'){


    if(attr.indexOf('rotate')!=-1 || attr.indexOf('skew')!=-1 || attr.indexOf('scale')!=-1 || attr.indexOf('translate')!=-1){
      return transform(el,attr,val);
    }

    //获取值
    if(typeof val == 'undefined'){
      let iVal = parseFloat(getComputedStyle(el)[attr]);
      return isNaN(iVal) ? null : iVal;
    }else{

      //设置值
      if(attr=='opacity'){
        el.style[attr] = val;
      }else{
        el.style[attr] = val + 'px';
      }

    }

  }else{
    return null;
  }

}


module.exports = css;
